/**
 * validate
 */

/**
 * validate mobile
 * @param mobile
 * @returns {boolean}
 */
export function validateMobile(mobile) {
  const re = /^09[0-9]{9}$/;
  return re.test(mobile);
}
export function validateMobile9(mobile) {
  const re = /^9[0-9]{9}$/;
  return re.test(mobile);
}
export function validateMobile639(mobile) {
  const re = /^639[0-9]{9}$/;
  return re.test(mobile);
}
export function validateMobileA639(mobile) {
  const re = /^\+639[0-9]{9}$/;
  return re.test(mobile);
}

/**
 * validate company phone
 * @param mobile
 * @returns {boolean}
 */
export function validateCompanyPhone(mobile) {
  const re = /^[0-9]{7,13}$/;
  return re.test(mobile);
}

/**
 * 校验身份证 15或18位
 * @param idCard
 * @returns {boolean}
 */
export function validateIdCard(idCard) {
  const re = /^((\d{17}|\d{14})[\d|X|x])$/;
  return re.test(idCard);
}

/**
 * 校验银行卡号 16，17，18，19位
 * @param card
 * @returns {boolean}
 */
export function validateBankCard(card) {
  const re = /^([1-9]{1})(\d{15}|\d{16}|\d{17}|\d{18})$/;
  return re.test(card);
}

/**
 * 校验数字
 * @param num
 * @returns {boolean}
 */
export function validateNumber(num) {
  const re = /^(\d)+$/;
  return re.test(num);
}

/**
 * validate email
 * @param email
 * @returns {boolean}
 */
export function validateEmail(email) {
  const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  return re.test(email);
}

/**
 * validate name
 * 只能以字母.空格组成不能含有数字或其他特殊字符
 * 必须以字母开头，允许出现的符号不能超过3位且不能相连，长度限制50字符不能为空
 * @param name
 * @returns {boolean}
 */
export function validateName(name) {
  const re = /^[a-zA-Z](?!.*[\s.]{2}.*)(?!.*([\s.].*){4,})[a-zA-Z\s.]{0,50}$/;
  return re.test(name);
}

/**
 * validate UMID
 * @param id
 * @returns {boolean}
 */
export function validateUMID(id) {
  const re = /^[0-9]{12}$/;
  return re.test(id);
}
export function validateUMID1(id) {
  const re = /^[0-9]{4}$/;
  return re.test(id);
}
export function validateUMID2(id) {
  const re = /^[0-9]{7}$/;
  return re.test(id);
}
export function validateUMID3(id) {
  const re = /^[0-9]$/;
  return re.test(id);
}

/**
 * validate passport
 * @param id
 * @returns {boolean}
 */
export function validatePassport(id) {
  const re = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{7,9}$/;
  return re.test(id);
}
export function validatePassport2(id) {
  const re = /^[a-zA-Z]\d{7}[a-zA-Z]$/;
  return re.test(id);
}

/**
 * validate TIN ID
 * @param id
 * @returns {boolean}
 */
export function validateTINID(id) {
  const re = /^[0-9]{9}$|^[0-9]{12}$/;
  return re.test(id);
}
export function validateTINID1(id) {
  const re = /^[0-9]{3}$/;
  return re.test(id);
}
export function validateTINID2(id) {
  const re = /^[0-9]{3}$|^[0-9]{5}$/;
  return re.test(id);
}

/**
 * validate Driver’s License
 * @param id
 * @returns {boolean}
 */
export function validateDriver(id) {
  const re = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{11}$/;
  return re.test(id);
}
export function validateDriver1(id) {
  const re = /^[a-zA-Z]\d{2}$/;
  return re.test(id);
}
export function validateDriver2(id) {
  const re = /^[0-9]{2}$/;
  return re.test(id);
}
export function validateDriver3(id) {
  const re = /^[0-9]{6}$/;
  return re.test(id);
}

/**
 * validate SSS ID
 * @param id
 * @returns {boolean}
 */
export function validateSSSID(id) {
  const re = /^[0-9]{10}$/;
  return re.test(id);
}
export function validateSSSID1(id) {
  const re = /^[0-9]{2}$/;
  return re.test(id);
}
export function validateSSSID2(id) {
  const re = /^[0-9]{7}$/;
  return re.test(id);
}
export function validateSSSID3(id) {
  const re = /^[0-9]$/;
  return re.test(id);
}

/**
 * validate postal ID
 * @param id
 * @returns {boolean}
 */
export function validatePostalIDFirst(id) {
  const re = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{12}$/;
  return re.test(id);
}
export function validatePostalIDSecond(id) {
  const re = /^[a-zA-Z]{1}$/;
  return re.test(id);
}
export function validatePostalID1(id) {
  const re = /^[a-zA-Z]\d{11}$/;
  return re.test(id);
}
export function validatePostalID2(id) {
  const re = /^[a-zA-Z]$/;
  return re.test(id);
}

/**
 * validate PRC ID
 * @param id
 * @returns {boolean}
 */
export function validatePRCID(id) {
  const re = /^[0-9]{7}$/;
  return re.test(id);
}

/**
 * validate GSIS ID
 * @param id
 * @returns {boolean}
 */
export function validateGSUSID(id) {
  const re = /^[0-9]{11}$/;
  return re.test(id);
}

/**
 * validate OWWA ID
 * @param id
 * @returns {boolean}
 */
export function validateOWWAID(id) {
  const re = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{2,50}$/;
  return re.test(id);
}
export function validateOWWAID1(id) {
  const re = /^[0-9]{8}$/;
  return re.test(id);
}
export function validateOWWAID2(id) {
  const re = /^[0-9]{2}$/;
  return re.test(id);
}

/**
 * validate National ID
 * @param id
 * @returns {boolean}
 */
export function validateNationalID(id) {
  const re = /^[0-9]{4}$/;
  return re.test(id);
}

/**
 * validate Philhealth ID
 * @param id
 * @returns {boolean}
 */
export function validatePhilhealthID1(id) {
  const re = /^[0-9]{2}$/;
  return re.test(id);
}
export function validatePhilhealthID2(id) {
  const re = /^[0-9]{9}$/;
  return re.test(id);
}
export function validatePhilhealthID3(id) {
  const re = /^[0-9]$/;
  return re.test(id);
}

/**
 * validate Voters ID
 * @param id
 * @returns {boolean}
 */
export function validateVotersID(id) {
  const re = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{22}$/;
  return re.test(id);
}
export function validateVotersIDFirst(id) {
  const re = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{4}$/;
  return re.test(id);
}
export function validateVotersIDSecond(id) {
  const re = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{5}$/;
  return re.test(id);
}
export function validateVotersIDThird(id) {
  const re = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{7}$/;
  return re.test(id);
}
export function validateVoterID1(id) {
  const re = /^[0-9]{4}$/;
  return re.test(id);
}
export function validateVoterID2(id) {
  const re = /^\d{4}[a-zA-Z]$/;
  return re.test(id);
}
export function validateVoterID3(id) {
  const re = /^[a-zA-Z]\d{4}[a-zA-Z]{3}\d{5}$/;
  return re.test(id);
}

/**
 * 详细地址校验 以字母数字空格-.组成，最大500字符不能为空
 * @param address
 * @returns {boolean}
 */
export function validateAddress(address) {
  const re = /^[a-zA-Z\d][a-zA-Z\d\s-.]{0,500}$/;
  return re.test(address);
}

